<%@ taglib prefix="page" uri="http://com.qipay/pagelib" %>
<%@ page language="java" import="com.qipay.admin.tags.PageModel" contentType="text/html;charset=utf-8" %>
<%@ page import="com.qipay.admin.utils.SiteHelper" %>
<%@ page import="com.qipay.baas.model.Sp" %>
<%@ page import="org.apache.commons.lang3.StringUtils" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="java.util.List" %>
<%@ page import="com.qipay.admin.sp.vo.SpUserDTO" %>
<%@ page import="com.qipay.core.entity.Pagination" %>
<!doctype html>
<html>
<head>
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <jsp:include page="head.jsp"></jsp:include>
    <link rel="stylesheet" href="<%= request.getAttribute("StaticHost") %>/css/dataTables.bootstrap.min.css">
    <link rel="stylesheet" href="<%= request.getAttribute("StaticHost") %>/css/list.css">
    <script type="text/javascript">
        //document.getElementsByTagName("html")[0].style.width=screen.availWidth/100+"px";
        document.getElementsByTagName("html")[0].style.fontSize = screen.availWidth / 200 + "px";
    </script>
    <style type="text/css">
        .border {
            border: 1px solid red;
        }
    </style>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <jsp:include page="nav.jsp"></jsp:include>
    <jsp:include page="left.jsp"></jsp:include>
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-md-12">
                    <div class="box">
                        <div class="box-header">
                            <h3 class="box-title">供号商列表</h3>
                            <button type="button" class="button back-gray" style="font-size: 1rem"
                                    data-toggle="modal"
                                    data-target="#addSpuserModal">
                                添加供号商
                            </button>
                        </div>
                        <%--<div>
                                <div class="new-group">
                                    <label> SP名称：</label>
                                <input type="text" id="txtName" value="<%= request.getParameter("name")!=null?request.getParameter("name"):""%>"/>
                                </div>
                                <div class="new-group">
                                <label> 服务：</label>
                                <input type="text" id="txtPerson" value="<%= request.getParameter("service")!=null?request.getParameter("service"):""%>"/>
                                </div>
                                <div class="new-group">
                                    <label> 渠道：</label>
                                <input type="text" id="txtContract" value="<%= request.getParameter("bank")!=null?request.getParameter("bank"):""%>"/>
                                </div>
                                <div class="new-group">
                                    <label> 状态：</label>
                                <select id="ddltype">
                                    <option value="-1">全部</option>
                                    <option value="0">正常</option>
                                    <option value="1">禁用</option>
                                </select>
                                </div>
                                <button type="button" class="button back-gray" id="btnSearch" style="font-size: 1rem">查询</button>
                            <div style="clear: both"></div>
                        </div>--%>
                        <!-- /.box-header -->
                        <div class="tableContent">
                            <table id="example2" class="table table-bordered table-hover">
                                <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>账号</th>
                                    <th>级别</th>
                                    <th>供号商名称</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>

                                <% List<SpUserDTO> spUserDTOS = (List<SpUserDTO>) request.getAttribute("spUsers");

                                    Pagination pager = (Pagination) request.getAttribute("page");
                                    String myPath=pageContext.getRequest().getServletContext().getContextPath();
                                    String query = myPath + "/spUser/query";
                                    if (spUserDTOS != null && spUserDTOS.size() > 0) {
                                        for (SpUserDTO s : spUserDTOS) {
                                %>

                                <tr id="user_<%=s.getId()%>">
                                    <td><%=s.getId()%>
                                    </td>
                                    <td>
                                        <% if (s.getLevel() != 1000) {%>
                                        <a href="${pageContext.request.contextPath}/sys/user/<%= s.getName()%>"><%=s.getName()%>
                                        </a>
                                        <%} else {%><%= s.getName()%><%}%>
                                    </td>
                                    <td>
                                        <%= SiteHelper.getUserLevelStrByLevel(s.getLevel())%>
                                    </td>
                                    <td><%=s.getspUserName()%>
                                    <td>
                                    <a class="button back-gray btn-xs" href="<%=myPath%>/sp?spUserName=<%=s.getName()%>"
                                    >查看sp列表</a>
                                        <a class="button back-gray btn-xs" href="javascript:spUserDel(<%= s.getName()%>)"
                                           >删除</a>
                                    </td>
                                </tr>
                                <%
                                    }
                                } else {
                                %>
                                <tr>
                                    <td colspan="4">no11 data.<%=spUserDTOS.size()%>
                                    </td>
                                </tr>
                                <% }%>
                                </tbody>
                            </table>
                            <div class="col-sm-10">
                                <div class="dataTables_paginate paging_simple_numbers" id="example1_paginate">
                                    <page:page totalSum="<%= pager.getTotal()%>"
                                               url="<%= query%>"
                                               pageNo="<%= pager.getPage()%>"
                                               pageSize="<%= pager.getPageSize()%>"></page:page>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </div>
    <!-- /.content-wrapper -->
    <jsp:include page="foot.jsp"></jsp:include>
    <!-- Modal 新增模态-->
    <div class="modal fade" id="addSpuserModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title control-label" id="newWhiteIpsModallabel">添加新的供号商</h4>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal" action="save" method="POST" id="doc-vld-msg">

                        <div class="box-body" id="dvContent">
                            <div class="form-group form-group-md">
                                <label for="txtNewSpUserName" class="col-sm-3 control-label">供号商名称：</label>
                                <div class="col-sm-9">
                                    <input class="form-control" type="" id="txtNewSpUserName" maxlength="20"
                                           name="newSpUserName"
                                           data-validation-message="请输入供号商名称" required>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">放弃</button>
                    <button type="button" class="btn btn-primary" id="addSpuserModalSureBtn">提交</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="<%= request.getAttribute("StaticHost") %>/js/jquery.slimscroll.min.js"></script>
<script src="<%= request.getAttribute("StaticHost") %>/js/fastclick.js"></script>
<script src="<%= request.getAttribute("StaticHost") %>/js/adminlte.min.js"></script>
<script>
    //确定标记删除
    function spUserDel(myname) {
        if (!!myname) {
            if (confirm("确定删除吗？")) {
                $.ajax({
                    url: "${pageContext.request.contextPath}/spUser/delete",
                    type: "POST",
                    data: {name: myname},
                    dataType: 'json',
                    async: true,//true异步 false同步
                    context: this,
                    timeout: 10000,
                    success: function (data) {
                        alert(data.msg);
                        window.location.href = "${pageContext.request.contextPath}/spUser/query";
                    },
                    error: function (d, s, b) {
                        alert("失败:" + b);
                    }
                });
            }
        }
    }

    $(function () {
        //绑定,新增模态的确定方法
        $("#addSpuserModalSureBtn").on("click", function () {
            var txtNewSpUserName = $.trim($("#txtNewSpUserName").val()) || "";

            if (txtNewSpUserName == "") {
                alert("请输入供号商名称");
                return false;
            }

            var that = this;
            $(that).attr("disabled", "disabled");
            $.ajax({
                type: 'POST',
                url: contextPath + "/spUser/add",
                data: { spUserName: txtNewSpUserName},
                dataType: "json",
                success: function (data) {
                    console.log(data);
                    if (data) {
                        if (data.code == 200) {
                            alert(data.message);
                            window.location.href = "${pageContext.request.contextPath}/spUser/query";
                            return;
                        }
                        alert(data.message);
                        $(that).removeAttr("disabled");
                    } else {
                        alert(data.message);
                        $(that).removeAttr("disabled");
                    }
                },
                error: function (error) {
                    console.log(error);
                    alert('服务器异常，请稍后再试！');
                    $(that).removeAttr("disabled");
                }
            })
        });
    });

</script>
</body>
</html>

